home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / sticpsrc.lzh / SOURCE.ARC / LAPBTIME.C < prev    next >
C/C++ Source or Header  |  1989-09-02  |  3KB  |  107 lines

  1. #include "global.h"
  2. #include "mbuf.h"
  3. #include "ax25.h"
  4. #include "timer.h"
  5. #include "lapb.h"
  6.  
  7. /* Called whenever timer T1 expires */
  8. void
  9. recover(n)
  10. int *n;
  11. {
  12.     register struct ax25_cb *axp;
  13.     char control;
  14.     struct mbuf *bp;
  15.     int len;
  16.     void lapbstate();
  17.  
  18.     axp = (struct ax25_cb *)n;
  19.     if (axp->n2 != 0 && axp->retries++ >= axp->n2){
  20.         /* Retry count exceeded, drop the link.
  21.          * Note that this is a change from the original AX.25
  22.          * spec; attempting to restart the link caused more
  23.          * problems than it solved.
  24.          */
  25.         lapbstate(axp,DISCONNECTED,LAPBFAIL);
  26.         del_ax25(axp);
  27.         return;
  28.     }
  29.     switch(axp->state){
  30.     case SETUP:
  31.         sendctl(axp,COMMAND,SABM|PF);
  32.         break;
  33.     case DISCPENDING:
  34.         sendctl(axp,COMMAND,DISC|PF);
  35.         break;
  36.     case CONNECTED:
  37.         /* Don't wait for a Final reply if running the old protocol */
  38.         if(axp->proto == V2)
  39.         axp->waitack = YES;
  40.  
  41.         /* I believe that retransmitting the oldest unacked
  42.          * I-frame tends to give better performance than polling,
  43.          * as long as the frame isn't too "large", because
  44.          * chances are that the I frame got lost anyway.
  45.          * This is an option in LAPB, but not in the official AX.25.
  46.          * When oldest unacked I-frame smaller than PTHRESH, use info poll */
  47.         if(axp->txq != NULLBUF &&
  48.         (((len = len_mbuf(axp->txq)) < axp->pthresh && !axp->remotebusy && axp->retries < 3) ||
  49.          axp->proto == V1)){
  50.         /* Retransmit oldest unacked I-frame */
  51.         bp = copy_p(axp->txq,len);
  52.         control = PF | I | (((axp->vs - axp->unack) & MMASK) << 1)
  53.             | (axp->vr << 5);
  54.         sendframe(axp,COMMAND,control,bp);
  55.         } else {
  56.         /* Transmit poll */
  57.         control = len_mbuf(axp->rxq) > axp->window? RNR|PF : RR|PF;
  58.         sendctl(axp,COMMAND,control);
  59.         }
  60.         break;
  61.     case FRAMEREJECT:
  62.         frmr(axp,0,0);        /* Retransmit last FRMR */
  63.         break;
  64.     }
  65. }
  66.  
  67. /* T2 has expired, we can't delay an acknowledgement any further */
  68. void
  69. send_ack(n)
  70. int *n;
  71. {
  72.     char control;
  73.     register struct ax25_cb *axp;
  74.     struct mbuf *bp;
  75.  
  76.     axp = (struct ax25_cb *)n;
  77.  
  78.     /* Now look if any valid frames are still in the sammler.  This means */
  79.     /* they were received earlier, and not repeated during T2 */
  80.     while ((bp = axp->sammlq[axp->vr]) != NULLBUF){
  81.         axp->sammlq[axp->vr] = NULLBUF;
  82.         axp->vr = (axp->vr+1) & MMASK;
  83.         procdata(axp,bp);        /* accept the frame */
  84.     }
  85.  
  86.     control = len_mbuf(axp->rxq) > axp->window ? RNR : RR;
  87.     sendctl(axp,RESPONSE,control);
  88.     axp->response = 0;
  89. }
  90.  
  91. /* Send a poll (S-frame command with the poll bit set) */
  92. void
  93. pollthem(n)
  94. int *n;
  95. {
  96.     char control;
  97.     register struct ax25_cb *axp;
  98.  
  99.     axp = (struct ax25_cb *)n;
  100.     if(axp->proto == V1)
  101.         return;            /* Not supported in the old protocol */
  102.     axp->waitack = YES;
  103.     control = len_mbuf(axp->rxq) > axp->window? RNR|PF : RR|PF;
  104.     sendctl(axp,COMMAND,control);
  105. }
  106.  
  107.